home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / include / Embryo.h < prev    next >
Encoding:
C/C++ Source or Header  |  2006-01-09  |  5.8 KB  |  131 lines

  1. #ifndef _EMBRYO_H
  2. #define _EMBRYO_H
  3.  
  4. #ifdef EAPI
  5. #undef EAPI
  6. #endif
  7. #ifdef WIN32
  8. # ifdef BUILDING_DLL
  9. #  define EAPI __declspec(dllexport)
  10. # else
  11. #  define EAPI __declspec(dllimport)
  12. # endif
  13. #else
  14. # ifdef __GNUC__
  15. #  if __GNUC__ >= 4
  16. #   define EAPI __attribute__ ((visibility("default")))
  17. #  else
  18. #   define EAPI
  19. #  endif
  20. # else
  21. #  define EAPI
  22. # endif
  23. #endif
  24.  
  25. #ifdef  __cplusplus
  26. extern "C" {
  27. #endif
  28.  
  29.    /* potentioal error values */
  30.    enum
  31.      {
  32.     EMBRYO_ERROR_NONE,
  33.       /* reserve the first 15 error codes for exit codes of the abstract machine */
  34.       EMBRYO_ERROR_EXIT,         /** Forced exit */
  35.       EMBRYO_ERROR_ASSERT,       /** Assertion failed */
  36.       EMBRYO_ERROR_STACKERR,     /** Stack/heap collision */
  37.       EMBRYO_ERROR_BOUNDS,       /** Index out of bounds */
  38.       EMBRYO_ERROR_MEMACCESS,    /** Invalid memory access */
  39.       EMBRYO_ERROR_INVINSTR,     /** Invalid instruction */
  40.       EMBRYO_ERROR_STACKLOW,     /** Stack underflow */
  41.       EMBRYO_ERROR_HEAPLOW,      /** Heap underflow */
  42.       EMBRYO_ERROR_CALLBACK,     /** No callback, or invalid callback */
  43.       EMBRYO_ERROR_NATIVE,       /** Native function failed */
  44.       EMBRYO_ERROR_DIVIDE,       /** Divide by zero */
  45.       EMBRYO_ERROR_SLEEP,        /** Go into sleepmode - code can be restarted */
  46.       
  47.       EMBRYO_ERROR_MEMORY = 16,  /** Out of memory */
  48.       EMBRYO_ERROR_FORMAT,       /** Invalid file format */
  49.       EMBRYO_ERROR_VERSION,      /** File is for a newer version of the Embryo_Program */
  50.       EMBRYO_ERROR_NOTFOUND,     /** Function not found */
  51.       EMBRYO_ERROR_INDEX,        /** Invalid index parameter (bad entry point) */
  52.       EMBRYO_ERROR_DEBUG,        /** Debugger cannot run */
  53.       EMBRYO_ERROR_INIT,         /** Embryo_Program not initialized (or doubly initialized) */
  54.       EMBRYO_ERROR_USERDATA,     /** Unable to set user data field (table full) */
  55.       EMBRYO_ERROR_INIT_JIT,     /** Cannot initialize the JIT */
  56.       EMBRYO_ERROR_PARAMS,       /** Parameter error */
  57.       EMBRYO_ERROR_DOMAIN,       /** Domain error, expression result does not fit in range */
  58.      };
  59.  
  60.    /* possible function type values that are enumerated */
  61. #define EMBRYO_FUNCTION_NONE 0x7fffffff /* An invalid/non existant function */
  62. #define EMBRYO_FUNCTION_MAIN -1         /* Start at program entry point */
  63. #define EMBRYO_FUNCTION_CONT -2         /* Continue from last address */
  64.   /** An invalid cell reference */
  65. #define EMBRYO_CELL_NONE     0x7fffffff 
  66.    /* program run return values */
  67. #define EMBRYO_PROGRAM_OK      1
  68. #define EMBRYO_PROGRAM_SLEEP   2
  69. #define EMBRYO_PROGRAM_BUSY    3
  70. #define EMBRYO_PROGRAM_TOOLONG 4
  71. #define EMBRYO_PROGRAM_FAIL    0
  72.  
  73.    typedef unsigned int                Embryo_UCell;
  74.    typedef int                         Embryo_Cell;
  75.    typedef struct _Embryo_Program      Embryo_Program;
  76.    typedef int                         Embryo_Function;
  77.  
  78.    typedef union
  79.      {
  80.     float       f;
  81.     Embryo_Cell c;
  82.      } Embryo_Float_Cell;
  83.  
  84. /** Float to Embryo_Cell */
  85. #define EMBRYO_FLOAT_TO_CELL(f) ((Embryo_Float_Cell) f).c
  86. /** Embryo_Cell to float */
  87. #define EMBRYO_CELL_TO_FLOAT(c) ((Embryo_Float_Cell) c).f
  88.    
  89.    EAPI int              embryo_init(void);
  90.    EAPI int              embryo_shutdown(void);
  91.    
  92.    EAPI Embryo_Program  *embryo_program_new(void *data, int size);
  93.    EAPI Embryo_Program  *embryo_program_const_new(void *data, int size);
  94.    EAPI Embryo_Program  *embryo_program_load(char *file);
  95.    EAPI void             embryo_program_free(Embryo_Program *ep);
  96.    EAPI void             embryo_program_native_call_add(Embryo_Program *ep, char *name, Embryo_Cell (*func) (Embryo_Program *ep, Embryo_Cell *params));
  97.    EAPI void             embryo_program_vm_reset(Embryo_Program *ep);
  98.    EAPI void             embryo_program_vm_push(Embryo_Program *ep);
  99.    EAPI void             embryo_program_vm_pop(Embryo_Program *ep);
  100.    EAPI void             embryo_swap_16(unsigned short *v);
  101.    EAPI void             embryo_swap_32(unsigned int *v);
  102.    EAPI Embryo_Function  embryo_program_function_find(Embryo_Program *ep, char *name);
  103.    EAPI Embryo_Cell      embryo_program_variable_find(Embryo_Program *ep, char *name);
  104.    EAPI int              embryo_program_variable_count_get(Embryo_Program *ep);
  105.    EAPI Embryo_Cell      embryo_program_variable_get(Embryo_Program *ep, int num);
  106.    EAPI void             embryo_program_error_set(Embryo_Program *ep, int error);
  107.    EAPI int              embryo_program_error_get(Embryo_Program *ep);
  108.    EAPI void             embryo_program_data_set(Embryo_Program *ep, void *data);
  109.    EAPI void            *embryo_program_data_get(Embryo_Program *ep);
  110.    EAPI const char      *embryo_error_string_get(int error);
  111.    EAPI int              embryo_data_string_length_get(Embryo_Program *ep, Embryo_Cell *str_cell);
  112.    EAPI void             embryo_data_string_get(Embryo_Program *ep, Embryo_Cell *str_cell, char *dst);
  113.    EAPI void             embryo_data_string_set(Embryo_Program *ep, char *src, Embryo_Cell *str_cell);
  114.    EAPI Embryo_Cell     *embryo_data_address_get(Embryo_Program *ep, Embryo_Cell addr);
  115.    EAPI Embryo_Cell      embryo_data_heap_push(Embryo_Program *ep, int cells);
  116.    EAPI void             embryo_data_heap_pop(Embryo_Program *ep, Embryo_Cell down_to);
  117.    EAPI int              embryo_program_recursion_get(Embryo_Program *ep);
  118.    EAPI int              embryo_program_run(Embryo_Program *ep, Embryo_Function func);
  119.    EAPI Embryo_Cell      embryo_program_return_value_get(Embryo_Program *ep);
  120.    EAPI void             embryo_program_max_cycle_run_set(Embryo_Program *ep, int max);
  121.    EAPI int              embryo_program_max_cycle_run_get(Embryo_Program *ep);
  122.    EAPI int              embryo_parameter_cell_push(Embryo_Program *ep, Embryo_Cell cell);
  123.    EAPI int              embryo_parameter_string_push(Embryo_Program *ep, char *str);
  124.    EAPI int              embryo_parameter_cell_array_push(Embryo_Program *ep, Embryo_Cell *cells, int num);
  125.    
  126. #ifdef  __cplusplus
  127. }         
  128. #endif
  129.  
  130. #endif
  131.